package ${basePackage}.service.impl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.beans.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import ${basePackage}.domain${m.prefixPoint(table.modelName)}.${table.className};
import ${basePackage}.domain${m.prefixPoint(table.modelName)}.${table.className}Vo;
import ${basePackage}.api.service.${table.className}JsfService;

/**
 * @author ${author!}
 * @since ${timeNow!}
 * ${table.remarks!}
 */
@Slf4j
@Service
public class ${table.className}JsfServiceImpl implements ${table.className}JsfService {
    @Resource
    private ${table.className}Service ${table.classNameFirstLower}Service;

    @Override
    public APIResult<${table.className+'Vo'}> queryById(Long id) {
        log.info("${table.className}JsfServiceImpl.queryById,通过id查询,id:{}",id);
        try {
            ${table.className+'Vo'} res = ${table.classNameFirstLower}Service.queryById(id);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    @Override
    public APIResult<${table.className+'Vo'}> queryForObject(${table.className}Vo query) {
        log.info("${table.className}JsfServiceImpl.queryForObject,根据条件查询对象,${table.className}Vo:{}",query);
        try {
            ${table.className+'Vo'} res = ${table.classNameFirstLower}Service.queryForObject(query);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    @Override
    public APIResult<List<${table.className+'Vo'}>> queryForList(${table.className}Vo query) {
        log.info("${table.className}JsfServiceImpl.queryForList,查询列表,${table.className}Vo:{}",query);
        try {
            List<${table.className+'Vo'}> res = ${table.classNameFirstLower}Service.queryForList(query);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    @Override
    public APIResult<PageResultVo<${table.className+'Vo'}>> queryPageList(${table.className}Vo query){
        log.info("${table.className}JsfServiceImpl.queryPageList,查询列表,${table.className}Vo:{}",query);
        try {
            PageResultVo<${table.className+'Vo'}> res = ${table.classNameFirstLower}Service.queryPageList(query);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    @Override
    public APIResult<Long> insert(${table.className}Vo entityVo) {
        log.info("${table.className}JsfServiceImpl.insert,新增,${table.className}Vo:{}",entityVo);
        try {
            ${table.className} entity =new ${table.className}();
            BeanUtils.copyProperties(entityVo,entity);
            Long res = ${table.classNameFirstLower}Service.insert(entity);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    @Override
    public APIResult<Integer> update(${table.className}Vo entityVo) {
        log.info("${table.className}JsfServiceImpl.update,更新,${table.className}Vo:{}", entityVo);
        try {
            ${table.className} entity = new ${table.className}();
            BeanUtils.copyProperties(entityVo,entity);
            Integer res = ${table.classNameFirstLower}Service.update(entity.getId(), entity);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    @Override
    public APIResult<Integer> deleteById(Long id){
        log.info("${table.className}JsfServiceImpl.deleteById,根据id删除,id:{}",id);
        try {
            Integer res = ${table.classNameFirstLower}Service.deleteById(id);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }
    @Override
    public APIResult<Long> save(${table.className}Vo param) {
        log.info("${table.className}JsfServiceImpl.save,保存,param:{}",param);
        try {
            Long res = ${table.classNameFirstLower}Service.save(param);
            return APIResult.success(res);
        }catch (BaseException e){
            return APIRes.error(e);
        }
    }

}